﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using MvcAtletIS.Models;
using PagedList;

namespace MvcAtletIS.Controllers
{
    public class ArticlesController : Controller
    {
        private atletisEntities db = new atletisEntities();
        
        // GET: /Articles/
        public ActionResult Index(int selectedYear = 0, int selectedMonth = 0)
        {
            if (selectedYear == 0)
                selectedYear = DateTime.Now.Year;

            if (selectedMonth == 0)
                selectedMonth = DateTime.Now.Month;
            
            ViewBag.selectedYear = new SelectList(db.Years, "Year", "Year", selectedYear);
            ViewBag.selectedMonth = new SelectList(Months.GetMonths(), "ID", "Name", selectedMonth);

            var model = db.Articles.Where(a => a.Date.Value.Year == selectedYear & a.Date.Value.Month == selectedMonth).OrderByDescending(a => a.Date).ToList();
            return View(model);
        }

        // GET: /Articles/Detail/1
        public ActionResult Detail(int ArticleId)
        {
            Articles model = db.Articles.SingleOrDefault(a => a.ID == ArticleId);
            if (model == null)
            {
                return HttpNotFound();
            }
            return View(model);
        }

    }
}
